package com.dimeng;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.webkit.WebView;

import com.dimeng.utils.Constant;

/**
 *@author:518ad-ccn
 *date:Mar 29, 2012
 *describe:加载url的页面地址
 */
public abstract class LoadDataSuperActivity extends SuperActivity{
	private static final long serialVersionUID = 7421528343005025257L;
	public String url = null;
	WebView webView = null;
	public MyTask mTask = null;
	
	public abstract void loadData();
	
	@Override
	protected void onDestroy (){
	    if (mTask != null){
	    	mTask.mDialog.cancel();
	        if (mTask.getStatus() != AsyncTask.Status.FINISHED)
	        	mTask.cancel(true); //cancel AsyncTask
	    }
	    super.onDestroy();
	}

	
	@Override
	public Object onRetainNonConfigurationInstance() {
        if(mTask != null){
            mTask.mDialog.dismiss();
        }
        return mTask;

	}
	
	class MyTask extends AsyncTask<Void, Void, Void>{
        private ProgressDialog mDialog;
        private LoadDataSuperActivity mContext;
        public MyTask(LoadDataSuperActivity context){
            super();
            mContext = context;
            if(null == webView){
            	webView = new WebView(mContext);
            }
        }
        
        protected void onPreExecute() {
            mDialog = ProgressDialog.show(mContext, null,Constant.LOADING);
            mDialog.setCancelable(true);
            loadData();
            mDialog.dismiss();
        }

        protected void onPostExecute(Void result) {
            mContext.mTask = null;
        }

        @Override
        protected Void doInBackground(Void... params) {
            SystemClock.sleep(5000);
            return null;
        }


		public ProgressDialog getmDialog() {
			return mDialog;
		}       
    }

}
